package com.wolf.api.main;

import java.io.IOException;
import java.io.InputStream;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import com.wolf.api.controller.ApiController;
import com.wolf.server.APIMain;
import com.wolf.server.LogServer;
import com.wolf.server.OtherServer;
import com.wolf.server.RefController;

public class MyApiMain {

	public static void main(String[] args) {
		//String path = DeptMain.class.getClass().getResource("/").getPath()+"/WebConfig.xml";
		InputStream in1 = null;
		try {
			InputStream in = MyApiMain.class.getResourceAsStream("/WebConfig.xml");
			in1 = MyApiMain.class.getResourceAsStream("/WebConfig.xml");
			if(in1!=null){
				SAXReader reader = new SAXReader();
				Document document = reader.read(in1);
				Element configE = document.getRootElement();
				String apiPort = configE.element("apiPort").getText();
				APIMain.port = Integer.parseInt(apiPort);
				APIMain.runs();//运行api文档服务器
			}
			regController();//运行注册器
			OtherServer.mains(in);//运行
			OtherServer.execServer();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(in1!=null){
				try {
					in1.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
	
	public static void regController(){//注册
		RefController.INSTANCE.putoList(new ApiController());
	}
	
}
